import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ThreadRes {

    public static String ConvertToString(InputStream inputStream){
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuilder result = new StringBuilder();
        String line = null;
        try {
            while((line = bufferedReader.readLine()) != null){
                result.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try{
                inputStreamReader.close();
                inputStream.close();
                bufferedReader.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
        return result.toString();
    }


    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            for(int i =0 ;i<3;i++)
            try {
                URL url = new URL("http://localhost:84/consumer/fallback/10");
                HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.connect();
                InputStream inputStream = urlConnection.getInputStream();
                String responseStr = ThreadRes.ConvertToString(inputStream);
                System.out.println(responseStr);
            } catch (IOException e) {
                e.printStackTrace();
            }
        };
        for(int i = 0;i < 100;i++){
            Thread thread1 = new Thread(runnable);
            Thread thread2 = new Thread(runnable);
            Thread thread3 = new Thread(runnable);
            thread1.start();
            thread2.start();
            thread3.start();
            System.out.println(i * 3);
//            thread3.join();
//            thread1.join();
//            thread2.join();
        }

    }
}
